package com.css.dzj.dzjfxyj.common.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 *拦截器规则
 * @author liangXG
 */
@Configuration
@PropertySource(value = "classpath:base.properties")
public class WebAppConfig implements WebMvcConfigurer {
    @Value("${LOGIN_EXCLUDE_PATH}")
    private String LOGIN_EXCLUDE_PATH;

    /***
     * 注入拦截逻辑
     * @return
     */
    @Bean
    LoginInterceptor getLoginInterceptor() {
        return new LoginInterceptor();
    }

    /***
     *配置拦截规则
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录白名单，不登录也不会被拦截的请求放到这里
        String[] login_exclude_path = LOGIN_EXCLUDE_PATH.split(",");

        InterceptorRegistration registration=registry.addInterceptor(getLoginInterceptor());
        //拦截所有请求
        registration.addPathPatterns("/**");
        //配置白名单
        registration.excludePathPatterns( );
    }
}
